package com.sg.xy.service.impl;

import com.sg.xy.pojo.AuthCode;
import com.sg.xy.service.AuthCodeService;
import com.sg.xy.service.CodeService;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;

@Service
public class CodeServiceImpl implements CodeService {

    @Autowired
    private AuthCodeService authCodeService;
    @Override
    public String validate(@PathVariable String email, @PathVariable String code) {
        AuthCode authCode = authCodeService.getByEmail(email);
        System.out.println(!authCode.getCode().equals(code));
        if (authCode == null || !authCode.getCode().equals(code)) {
            return "1";
        }
        if (authCode.getCreatetime().getTime() + 2 * 60 * 1000 < System.currentTimeMillis()) {
            return "2";
        }
        return "0";
    }
}
